Get Permission of AccessRec

Hi,

as part of a skript to set up access of one attribute to be equal to the access of another one it seems to me like I need to transform the access information from an AccessRec to a Permission "manually".

Does somebody here has a better solution for this:

/*
 * Build up Permission out of AccessRec
 */
Permission buildPermission(AccessRec ar) {
    Permission p 
        if(read(ar)) {
                p = read
        }
        if(create(ar)) {
                p = p | create
        }
        if(modify(ar)) {
                p = p | modify
        }
        if(delete(ar)) {
                p = p | delete
        }
        if(control(ar)) {
                p = p | control
        }
}
for ar in masterAd do {
        Permission p = buildPermission(ar)
        setDef(m, derivedAd, p, username(ar))
}

MichaelGeorg - Thu Apr 19 04:25:53 EDT 2012

Re: Get Permission of AccessRec
llandale - Thu Apr 19 12:44:39 EDT 2012

  • Permission p = none // in case access is "none"
No, everyone needs that sort of function. Also converting "Permission" to a string for display purposes.

-Louie

Re: Get Permission of AccessRec
MichaelGeorg - Fri Apr 20 05:40:50 EDT 2012

llandale - Thu Apr 19 12:44:39 EDT 2012

  • Permission p = none // in case access is "none"
No, everyone needs that sort of function. Also converting "Permission" to a string for display purposes.

-Louie

Also that's not what I hope for, thank you Louie for the information.
Probably it was too optimistic to expect some easier way in DXL. Anyhow as not only the initial ..."p = non" but also the return statement was missing here the code how I use it in my script:
 

/*
 * Build up Permission out of AccessRec
 */
Permission buildPermission(AccessRec ar) {
    Permission p = none
        if(read(ar)) {
                p = read
        }
        if(create(ar)) {
                p = p | create
        }
        if(modify(ar)) {
                p = p | modify
        }
        if(delete(ar)) {
                p = p | delete
        }
        if(control(ar)) {
                p = p | control
        }
        return p
}

Re: Get Permission of AccessRec
llandale - Fri Apr 20 11:37:21 EDT 2012

MichaelGeorg - Fri Apr 20 05:40:50 EDT 2012

Also that's not what I hope for, thank you Louie for the information.
Probably it was too optimistic to expect some easier way in DXL. Anyhow as not only the initial ..."p = non" but also the return statement was missing here the code how I use it in my script:
 

/*
 * Build up Permission out of AccessRec
 */
Permission buildPermission(AccessRec ar) {
    Permission p = none
        if(read(ar)) {
                p = read
        }
        if(create(ar)) {
                p = p | create
        }
        if(modify(ar)) {
                p = p | modify
        }
        if(delete(ar)) {
                p = p | delete
        }
        if(control(ar)) {
                p = p | control
        }
        return p
}

Just as a matter of style, I think the following is easier to understand more quickly:

Permission buildPermission(AccessRec ar) {
    if(null ar)         then return(none Permission)
 
        Permission           p = none
        if(read(ar))    then p = p | read
        if(create(ar))  then p = p | create
        if(modify(ar))  then p = p | modify
        if(delete(ar))  then p = p | delete
        if(control(ar)) then p = p | control
        return p
}


And maybe this code:

 

bool    hasPermission(AccessRec ar, Permission p)
{     // Does the Access rec provide the specified Permission?
        // e.g. if(hasPermission(ar, modify)) then the ar has 'modify' permission
 
        Permission psn = buildPermission(ar)
        return((psn & p)==p)
}


-Louie